#ifndef DATAPARSER_H
#define DATAPARSER_H

#include <QObject>
#include <QTime>
#include <pthread.h>
#include <unistd.h>
#include <iostream>
#include <QDebug>
#include "trdpthread.h"

#define MINMUM_CYCLE 50

class DataParser : public QObject
{
    Q_OBJECT
public:
    DataParser(TRDPThread *com);

    TRDPThread* getTRDPThread();
    void initCom();
    void startCom();
    void stopCom();
    int getComState();
    void startParser();
    void stopParser();
    void setSendVarValue(int comidIndex, int index, unsigned long value);
    void setSendVarValue(int comidIndex, uint byte, uint bit,unsigned long value);
    unsigned long getSendVarValue(int comidindex, int index);
    void setRecvVarValue(int comidIndex, int index, unsigned long value);
    unsigned long getRecvVarValueByIndex(int comidindex, int index);
    unsigned long getRecvVarValueByOffset(int comidindex,uint Byte, uint Bit);
    unsigned long getRecvVarValue(int comidIndex, int index);
    void setRecvEthVarValue(int byte, unsigned char value);

    int getRecvVarCount(int comidIndex);
    unsigned int getRecvVarByte(int comidIndex, int index);
    unsigned char getRecvVarBit(int comidIndex, int index);
    unsigned char getRecvVarSize(int comidIndex, int index);
    int getRecvVarIndex(int comidIndex, uint byte, uint bit);
    QString getRecvVarName(int comidIndex, int index);
    int getSendVarCount(int comidIndex);
    unsigned int getSendVarByte(int comidIndex, int index);
    unsigned char getSendVarBit(int comidIndex, int index);
    unsigned char getSendVarSize(int comidIndex, int index);
    QString getSendVarName(int comidIndex, int index);
    unsigned int getSendVarIndex(int comidIndex,uint byte,uint bit);
    uint getTime();
    TRDPThread *trdp;
signals:
    void signalVarChanged(int comidIndex, int index, unsigned long value);
private:
    QList< QList<unsigned long> > recvVar;
    QList< QList<unsigned long> > sendVar;
    QList<unsigned long> msgVar;
    bool xParseState;
    unsigned long readMemVar(int comidIndex, int byte, int bit, int size);
    void writeMemVar(int comidIndex, int byte, int bit, int size, unsigned long value);
    static void* parserThread(void *arg);

};

#endif // DATAPARSER_H
